/* indent size: 1 */

module.exports = app => {
	const DataTypes = app.Sequelize;

	const Model = app.model.define('auth_group', {
		id: {
			type: DataTypes.INTEGER(11),
			allowNull: false,
			primaryKey: true,
			autoIncrement: true
		},
		name: {
			type: DataTypes.STRING(30),
            allowNull: true,
		},
		describe: {
			type: DataTypes.STRING(30),
            allowNull: true,
		},
		createdAt: {
			type: DataTypes.DATE,
			allowNull: true
		},
		updatedAt: {
			type: DataTypes.DATE,
			allowNull: true
		},
		is_delete: {
			type: DataTypes.INTEGER(1).UNSIGNED,
			allowNull: false,
			defaultValue: '0',
			comment: '是否删除，0->存在，1->删除'
		},
	}, {
		tableName: 'auth_group',
		timestamps: false
	});

	Model.sync({ alter: true });
	Model.associate = function() {
		// 与auth-module表是多对多关系
		app.model.AuthGroup.belongsToMany(app.model.AuthModule, {
			through: app.model.AuthGroupModule,
			foreignKey: 'group_id',
			otherKey: 'module_id'
		});
		// 与auth-user表是多对多的关系
		app.model.AuthGroup.belongsToMany(app.model.AuthUser, {
			through: app.model.AuthUserGroup,
			foreignKey: 'group_id',
			otherKey: 'user_id'
		});
	};

	return Model;
};
